package com.bang.concurrency.example.publish;

import com.bang.concurrency.annotations.NotRecommend;
import com.bang.concurrency.annotations.NotThreadSafe;
import lombok.extern.slf4j.Slf4j;

/**
 * @Auther: Bang
 * @Date: 2019/9/30 21:04
 * @Description: 对象逃逸 当一个对象还没有构造完时,就使它被其他线程所见
 */
@Slf4j
@NotThreadSafe
@NotRecommend
public class Escape {

    private int thisCanBeEscape = 0;

    public Escape() {
        new InnerClass();
    }

    public Escape(int thisCanBeEscape) {
        new InnerClass();
        this.thisCanBeEscape = thisCanBeEscape;
    }

    private class InnerClass {

        public InnerClass() {
            log.error("{}", Escape.this.thisCanBeEscape);
        }
    }

    public static void main(String[] args) {
        new Escape(10);
    }
}
